<template>
  <div class="event-input">
    <!-- 基本信息 -->
    <div class="form-section">
      <div class="section-header">
        <i class="el-icon-edit"></i>
        <span>基本数据录入</span>
      </div>
      <div class="form-content">
        <div class="form-item">
          <label>事件名称</label>
          <el-input 
            v-model="formData.eventName" 
            placeholder="请输入事件名称"
            clearable
          ></el-input>
        </div>
        
        <div class="form-item">
          <label>事件类型</label>
          <el-select v-model="formData.eventType" placeholder="请选择事件类型" style="width: 100%">
            <el-option label="传染病疫情" value="传染病疫情"></el-option>
            <el-option label="食品安全事件" value="食品安全事件"></el-option>
            <el-option label="职业中毒" value="职业中毒"></el-option>
            <el-option label="环境污染" value="环境污染"></el-option>
            <el-option label="其他事件" value="其他事件"></el-option>
          </el-select>
        </div>

        <div class="form-item">
          <label>发生时间</label>
          <el-date-picker
            v-model="formData.occurTime"
            type="datetime"
            placeholder="选择日期时间"
            style="width: 100%"
            value-format="yyyy-MM-dd HH:mm:ss"
          ></el-date-picker>
        </div>

        <div class="form-item">
          <label>发生地点</label>
          <el-input 
            v-model="formData.location" 
            placeholder="请输入发生地点"
            clearable
          ></el-input>
        </div>
      </div>
    </div>

    <!-- 人员数据统计 -->
    <div class="form-section">
      <div class="section-header">
        <i class="el-icon-s-data"></i>
        <span>人员数据统计</span>
      </div>
      <div class="form-content">
        <div class="data-grid">
          <div class="data-item">
            <label>涉及人数</label>
            <el-input-number 
              v-model="formData.involvedCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>
          
          <div class="data-item">
            <label>新报告病例数</label>
            <el-input-number 
              v-model="formData.newCaseCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>排除病例数</label>
            <el-input-number 
              v-model="formData.excludedCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>在治人数</label>
            <el-input-number 
              v-model="formData.treatmentCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>密切接触人数</label>
            <el-input-number 
              v-model="formData.closeContactCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>次密接人数</label>
            <el-input-number 
              v-model="formData.subCloseContactCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>累计报告病例数</label>
            <el-input-number 
              v-model="formData.totalCaseCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>治愈人数</label>
            <el-input-number 
              v-model="formData.curedCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>死亡人数</label>
            <el-input-number 
              v-model="formData.deathCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>

          <div class="data-item">
            <label>新增死亡人数</label>
            <el-input-number 
              v-model="formData.newDeathCount" 
              :min="0" 
              controls-position="right"
              style="width: 100%"
            ></el-input-number>
          </div>
        </div>
      </div>
    </div>

    <!-- 简要描述 -->
    <div class="form-section">
      <div class="section-header">
        <i class="el-icon-document"></i>
        <span>简要描述</span>
      </div>
      <div class="form-content">
        <div class="form-item">
          <el-input 
            v-model="formData.briefDescription" 
            type="textarea"
            :rows="4"
            placeholder="请简要描述事件情况"
            maxlength="500"
            show-word-limit
          ></el-input>
        </div>
      </div>
    </div>

    <!-- 快捷数据统计卡片 -->
    <div class="stats-cards">
      <div class="stat-card">
        <div class="stat-icon" style="background: #409EFF;">
          <i class="el-icon-user"></i>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ formData.totalCaseCount || 0 }}</div>
          <div class="stat-label">累计病例</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon" style="background: #67C23A;">
          <i class="el-icon-success"></i>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ formData.curedCount || 0 }}</div>
          <div class="stat-label">治愈人数</div>
        </div>
      </div>

      <div class="stat-card">
        <div class="stat-icon" style="background: #E6A23C;">
          <i class="el-icon-warning"></i>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ formData.treatmentCount || 0 }}</div>
          <div class="stat-label">在治人数</div>
        </div>
      </div>

      <div class="stat-card">
        <div class="stat-icon" style="background: #F56C6C;">
          <i class="el-icon-close"></i>
        </div>
        <div class="stat-info">
          <div class="stat-value">{{ formData.deathCount || 0 }}</div>
          <div class="stat-label">死亡人数</div>
        </div>
      </div>
    </div>

    <!-- 操作按钮 -->
    <div class="action-buttons">
      <el-button 
        type="default" 
        size="large"
        @click="handleReset"
        style="flex: 1;"
      >
        重置
      </el-button>
      <el-button 
        type="primary" 
        size="large"
        @click="handleSave"
        style="flex: 2;"
      >
        保存续报信息
      </el-button>
    </div>
  </div>
</template>

<script>
import { saveEventReport } from './service';

export default {
  name: 'EventInput',
  
  data() {
    return {
      formData: {
        eventName: '',
        eventType: '',
        occurTime: '',
        location: '',
        involvedCount: 0,
        newCaseCount: 0,
        excludedCount: 0,
        treatmentCount: 0,
        closeContactCount: 0,
        subCloseContactCount: 0,
        totalCaseCount: 0,
        curedCount: 0,
        deathCount: 0,
        newDeathCount: 0,
        briefDescription: ''
      }
    };
  },

  methods: {
    handleSave() {
      // 数据验证
      if (!this.formData.eventName) {
        this.$message.warning('请输入事件名称');
        return;
      }
      if (!this.formData.eventType) {
        this.$message.warning('请选择事件类型');
        return;
      }
      if (!this.formData.occurTime) {
        this.$message.warning('请选择发生时间');
        return;
      }

      const loading = this.$loading({
        lock: true,
        text: '保存中...',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      saveEventReport(this.formData)
        .then(() => {
          loading.close();
          this.$notify({
            title: '✅ 保存成功',
            message: '事件续报信息已保存',
            type: 'success',
            duration: 2000,
            position: 'top-right',
            offset: 60
          });
          // 重置表单
          this.handleReset();
        })
        .catch(error => {
          loading.close();
          this.$message.error(error.message || '保存失败');
        });
    },

    handleReset() {
      this.formData = {
        eventName: '',
        eventType: '',
        occurTime: '',
        location: '',
        involvedCount: 0,
        newCaseCount: 0,
        excludedCount: 0,
        treatmentCount: 0,
        closeContactCount: 0,
        subCloseContactCount: 0,
        totalCaseCount: 0,
        curedCount: 0,
        deathCount: 0,
        newDeathCount: 0,
        briefDescription: ''
      };
      this.$message.info('表单已重置');
    }
  }
};
</script>

<style scoped>
.event-input {
  background: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 80px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.form-section {
  background: white;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-header {
  display: flex;
  align-items: center;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.section-header i {
  font-size: 20px;
  margin-right: 8px;
}

.form-content {
  padding: 15px;
}

.form-item {
  margin-bottom: 20px;
}

.form-item:last-child {
  margin-bottom: 0;
}

.form-item label {
  display: block;
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
  font-weight: 500;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.data-item label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 8px;
}

/* 统计卡片 */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 10px;
  background: white;
  margin-bottom: 10px;
}

.stat-card {
  display: flex;
  align-items: center;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-icon i {
  font-size: 24px;
  color: white;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  line-height: 1;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 12px;
  color: #999;
}

/* 操作按钮 */
.action-buttons {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 15px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  z-index: 100;
  display: flex;
  gap: 10px;
}

.action-buttons .el-button {
  border-radius: 6px;
  font-size: 15px;
  height: 46px;
  font-weight: 500;
}
</style>

